package com.wei.ssm.controller;

import com.wei.ssm.domain.Product;
import com.wei.ssm.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author wei
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @RequestMapping("/save.do")
    public String save(Product product){
        System.out.println(product);
        System.out.println("save. do");
        iProductService.save(product);
        //保存之后，重新回到查询列表
        return "redirect:findAll.do";
    }



    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        List<Product> all = iProductService.findAll();
        modelAndView.addObject("productList",all);
        modelAndView.setViewName("product-list1");
        return  modelAndView;
    }
}
